package com.example.demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.demo.DemoApplication;
import com.example.demo.model.entity.User;
import com.example.demo.service.UserService;
import com.fasterxml.jackson.databind.JsonSerializable.Base;
import com.example.demo.mapper.UserMapper;
import org.springframework.stereotype.Service;
import com.example.demo.common.BaseResponse;
import com.example.demo.common.ErrorCode;
import com.example.demo.common.ResultUtils;
import com.example.demo.model.dto.UserLoginRequest;
import com.example.demo.exception.ThrowUtils;

/**
* @author Administrator
* @description 针对表【user(用户)】的数据库操作Service实现
* @createDate 2025-06-25 21:30:36
*/
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService{

    @Override
    public BaseResponse<?> login(UserLoginRequest userLoginRequest) {
        if (userLoginRequest == null){
            return ResultUtils.error(ErrorCode.PARAMS_ERROR);
        }
        String userAccount = userLoginRequest.getUserAccount();
        String userPassword = userLoginRequest.getUserPassword();
        LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(User::getUseraccount, userAccount);
        queryWrapper.eq(User::getUserpassword, userPassword);
        User user = this.getOne(queryWrapper);
        if (user == null){
            return ResultUtils.error(ErrorCode.NOT_FOUND_ERROR);
        }
        return ResultUtils.success(user);
    }
}




